<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>搜索框内容自动提示</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .box {
            width: 300px;
            margin: 100px auto;
        }
        
        input {
            width: 100%;
            outline: none;
            height: 28px;
            line-height: 28px;
            font-size: 18px;
        }
        
        input:focus {
            border: 1px solid #2E9AFE;
        }
        
        li {
            list-style-type: none;
            line-height: 25px;
        }
        
        ul {
            width: 99.5%;
            border-width: 1px;
            border-style: solid;
            border-color: transparent #A4A4A4 #A4A4A4 #A4A4A4;
        }
        /* .list_box {
            display: none;
        } */
    </style>
    <script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
</head>

<body>
    <div class='box'>
        <input type="search" placeholder="请输入搜索关键字">
        <ul class='list_box'>
        </ul>
    </div>
    <script src="../template-web.js"></script>
    <script type='text/html' id='tpl'>
        <li>{{result}}</li>
    </script>
    <script>
        var search = document.querySelector('input');
        var list_box = document.querySelector('.list_box');
        // 文本框中输入内容时触发
        search.oninput = function() {
            var key = this.value;
            axios({
                url: '/search',
                method: 'get',
                params: {
                    key: key
                },
            }).then(res => {
                var result = res.data;

            }).catch(err => {
                // console.log(err);
            })
        }
    </script>
</body>

</html>